﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cvrt="clr-namespace:CustomSliderLib"
    xmlns:local="clr-namespace:CustomSliderLib">
    <Style x:Key="MySliderThumb" TargetType="{x:Type Thumb}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Rectangle Fill="Brown" Stroke="Transparent" StrokeThickness="0.5" 
                               Height="15" Width="5" RadiusX="3" RadiusY="3"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <cvrt:AbsoluteToRelativeConverter x:Key="Converter"></cvrt:AbsoluteToRelativeConverter>
    
    <Style x:Key="SliderRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Rectangle Fill="Transparent"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <SolidColorBrush x:Key="HorizontalSliderTrackNormalBackground" Color="#FFE7EAEA"/>
    <LinearGradientBrush x:Key="HorizontalSliderTrackNormalBorder" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFAEB1AF" Offset="0.1"/>
        <GradientStop Color="White" Offset=".9"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="TrackBg" EndPoint="1,0" StartPoint="0,0" >
        <GradientStop Color="{Binding Path=FillColor, RelativeSource={RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}}" Offset="0"/>
        <GradientStop Color="{Binding Path=FillColor, RelativeSource={RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}}" >
                <GradientStop.Offset>
                    <MultiBinding Converter="{StaticResource Converter}">
                        <Binding Path="Value" RelativeSource="{RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}"></Binding>
                        <Binding Path="Maximum" RelativeSource="{RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}"></Binding>
                    </MultiBinding>
                </GradientStop.Offset>
            </GradientStop>
            <GradientStop Color="{Binding Path=EmptyColor, RelativeSource={RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}}" >
                <GradientStop.Offset>
                    <MultiBinding Converter="{StaticResource Converter}">
                        <Binding Path="Value" RelativeSource="{RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}"></Binding>
                        <Binding Path="Maximum" RelativeSource="{RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}"></Binding>
                    </MultiBinding>
                </GradientStop.Offset>
            </GradientStop>
    </LinearGradientBrush>

    <Style x:Key="MySongSlider" TargetType="{x:Type Slider}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Slider}">
                    <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TickBar x:Name="TopTick" Visibility="Collapsed" Fill="{TemplateBinding Foreground}" Placement="Top" Height="4" Grid.Row="0"/>
                            <TickBar x:Name="BottomTick" Visibility="Collapsed" Fill="{TemplateBinding Foreground}" Placement="Bottom" Height="4" Grid.Row="0"/>
                            <Border x:Name="TrackBackground" 
                                    Background="{StaticResource TrackBg}"
                                    BorderBrush="{StaticResource HorizontalSliderTrackNormalBorder}"                                        
                                    BorderThickness="1" CornerRadius="2"
                                    Margin="0,0" VerticalAlignment="Center" Height="9.0" Grid.Row="1" >
                                <Canvas Margin="-6,-1">
                                    <Rectangle Visibility="Hidden" x:Name="PART_SelectionRange" Height="5.0"
                                               Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                               Stroke="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"
                                               StrokeThickness="1"/>
                                </Canvas>
                            </Border>
                            <Track x:Name="PART_Track" Grid.Row="1">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" BorderBrush="Black" 
                                                  BorderThickness="3" Command="{x:Static Slider.DecreaseLarge}"/>
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" 
                                                  Command="{x:Static Slider.IncreaseLarge}"/>
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb" Style="{StaticResource MySliderThumb}" Background="Black" />
                                </Track.Thumb>
                            </Track>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="{x:Type local:CustomSlider}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CustomSlider}">
                    <UniformGrid Columns="1">
                        <!--<Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" >
                            <Rectangle Height="{TemplateBinding Height}"
                            Width="{TemplateBinding Width}">
                                <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                        <GradientStop Color="{Binding Path=FillColor}"
                                                      Offset="0"/>
                                        <GradientStop Color="{Binding Path=FillColor}"
                                                      Offset="{Binding ElementName=slider, Path=Value}"/>
                                        <GradientStop Color="{Binding Path=EmptyColor}"
                                                      Offset="{Binding ElementName=slider, Path=Value}"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                        </Border>-->
                        <Slider Style="{StaticResource MySongSlider}" x:Name="slider" Width="Auto" 
                                IsMoveToPointEnabled="True" 
                                Value="{Binding Path=Value, RelativeSource={RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}}"
                                Minimum="{Binding Path=Minimum, RelativeSource={RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}}"
                                Maximum="{Binding Path=Maximum, RelativeSource={RelativeSource FindAncestor, AncestorType=cvrt:CustomSlider}}"
                                Height="Auto" />
                    </UniformGrid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
